<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>通过canvas绘制三角形</title>
</head>
<body>
    <canvas id="oCanvas" width="300px" height="300px" style="border:2px black solid"></canvas>
</body>

<script>
    //获取canvas对象
    var canvas = document.getElementById("oCanvas");
    //获取画笔对象
    var ctx = canvas.getContext('2d');
    
    //绘制三角形
    //1.新建一条路径
    ctx.beginPath();
    //2.设置初始点
    ctx.moveTo(100,100);
    //3.移动笔触
    ctx.lineTo(0,200);
    ctx.lineTo(200,200);
    // 4.2样式(填充颜色)，如果是描边 ctx.strokeStyle='#ff00ff';
    ctx.fillStyle='#00ff00';

    // 5.1 描边
        // //闭合路径
        // // ctx.lineTo(100,100);
        // ctx.closePath();
        // //5.描边
        // ctx.stroke();
    //5.2 填充
    ctx.fill();

</script>
</html>